<template>
  <div>
    <!--  面包屑  -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>竞赛活动</el-breadcrumb-item>
      <el-breadcrumb-item>编写公告</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 提交表单 -->
    <div style="margin-top: 20px">
      <el-form ref="form" :model="sizeForm1" label-width="80px" size="medium">
        <el-form-item label="活动标题">
          <el-input v-model="sizeForm1.name" style="width: 383px; float: left"></el-input>
        </el-form-item>
        <el-form-item label="相关赛事">
          <el-select v-model="sizeForm1.type" placeholder="请选择比赛" style="float: left; width: 383px" >
            <el-option label="C语言程序设计赛" value="C语言程序设计"></el-option>
            <el-option label="大学计算机" value="大学计算机"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动时间">
          <el-col :span="8">
            <el-date-picker type="date" placeholder="选择日期" v-model="sizeForm1.date" style="width: 100%;"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="活动内容">
          <tinymce v-model="sizeForm1.content"></tinymce>
        </el-form-item>
        <div style="width: 900px">
          <el-button type="primary" @click="onSubmit1" style="width: 100px">提交</el-button>
          <el-button @click="reset" style="width: 100px; margin-left: 150px">重置</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import Tinymce from '../components/Tinymce'
export default {
  name: 'CompetitionEdit',
  components: {Tinymce},
  // 不应该写在此方法里，暂未解决报错！！！！！！！！！！！
  mounted () {
    var query = this.$router.history.current.query
    if (query !== {}) {
      var row = query.row
      // console.log(row)
      this.sizeForm1.name = row.name
      this.sizeForm1.content = row.content
      this.sizeForm1.type = row.type
      this.sizeForm1.data = row.data
      this.sizeForm1.id = row.id
    }
  },
  data () {
    return {
      sizeForm1: {
        name: '',
        content: '',
        tpye: '',
        date: '',
        id: ''
      }
    }
  },
  methods: {
    onSubmit1 () {
      this.$axios({
        url: 'test/competition/edit',
        method: 'post',
        // headers: { Authorization: localStorage.getItem('tk') },
        data: this.sizeForm1
      }).then(res => {
        console.log(res.data)
        if (res.data === 1) {
          this.$message.success('成功！')
          this.sizeForm1 = {} // 这里必须赋值为一个空的对象，不能为" " ！！！不然Invalid prop: type check failed for prop "model".
        }
      })
    },
    reset () {
      this.sizeForm1 = {}
    }
  }
}
</script>

<style scoped>

</style>
